feat(#588): per-route request body size limits - #627
Merged
Abdulazeem-code merged 1 commit intoAug 29, 2026
Merged
Conversation
Apply endpoint-type specific body caps via a bodySizeLimit dispatcher: auth/register 1kb, bulk /payments & /webhooks 100kb, standard 10kb. Replaces the buggy duplicate global express.json parsers; oversized payloads now return 413 with a message naming the endpoint cap.
|
@ogaziedaniel80-droid is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@ogaziedaniel80-droid Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #588 — Applies per-route request body size limits instead of the previous uniform
express.json({ limit: '10kb' }).A new
bodySizeLimitdispatcher middleware (src/middleware/bodyLimit.js) chooses anexpress.jsoncap based on the request path:/auth/*) and/register/paymentsand/webhooksIn
server.jsthe previous duplicate global parsers were replaced with a singleapp.use(bodySizeLimit). The old code appliedexpress.json()(no limit) followed byexpress.json({ limit: '10kb' }); the second was a no-op because the body was already parsed, so the effective cap was ~100kb everywhere — this fixes that bug too.The 413 handler (
errorHandler.js) now reports the actual cap for the offending endpoint (e.g. "Payload too large. Maximum allowed size for this endpoint is 1kb.").Implementation note
The pinned
raw-body@2.5.3does not support limit-as-a-function, so the dispatcher forwards to three pre-built numeric-limit parsers keyed by path. This is independent of mount point, so/api/v1,/api, and/all get the correct tier.Test plan
tests/middleware/bodyLimit.test.js— 8 tests covering: auth 1kb reject/accept, bulk 100kb accept/reject, standard 10kb reject/accept, and non-JSON bodies left unparsed.Acceptance criteria
Suggested review areas
server.js,src/middleware/bodyLimit.js,src/routes/v1/paymentRoutes.js,src/routes/v1/webhookRoutes.js